<?php
lz_exit("暂时关闭注册！",'javascript:history.go(-1)',5);
include_once('model/user.php');
$user = new LZ_User;
$m = $_GET['m'];


if ($m == 'reg')
{
	$data = filter_array($_POST,'name!,lz_encode:password!,email');
	if (!$data || !$_POST['password'])
	{
		$err_msg = FILL_ALL;
	}
	else if ($data['password'] != lz_encode($_POST['password2']))
	{
		$err_msg = PASSWORD_NOT_THE_SAME;
	}
	else
	{
		if ($user->exists($data['name']))
		{
			$err_msg = USER_EXISTS;
		}
		else if ( $user->add($data) )
		{
			lz_exit(USER_NEW_SUCCESS,$_SESSION['last_page']?$_SESSION['last_page']:'index.php',1);
		}
		else
		{
			$err_msg = USER_NEW_ERROR;
		}
	}
}
else
{
	$_SESSION['last_page'] = (strpos($_SERVER['HTTP_REFERER'],'register') === false)?$_SERVER['HTTP_REFERER']:'index.php';
}


$view_data['err_msg'] = $err_msg;
$view_data['user'] = $_POST;
$view_data['title'] = REGISTER;
$view_data['page_description'] = REGISTER;
include_once('left.php');
?>